package com.seele.tigerwallet.ui.callback;

import android.support.design.widget.AppBarLayout;

import com.seele.tigerwallet.async.Log;

/**
 * 作者：huangshuyuan on 2017/5/16 11:17
 * 邮箱：hshuyuan@foxmail.com
 * 如何监听CollapsingToolbarLayout的展开与折叠
 */

public abstract class AppBarStateChangeListener implements AppBarLayout.OnOffsetChangedListener {

    private int mDif;

    public enum State {
        EXPANDED,
        COLLAPSED,
        IDLE
    }


    public AppBarStateChangeListener(int mDif) {
        this.mDif = mDif;
    }

    private State mCurrentState = State.IDLE;


    @Override
    public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {



//        if (Math.abs(i) >57){
//            onStateChanged(appBarLayout, State.IDLE,i);
//        }else if (i == 0) {
//            if (mCurrentState != State.EXPANDED) {
//                onStateChanged(appBarLayout, State.EXPANDED,i);
//            }
//            mCurrentState = State.EXPANDED;
//
//        }

        if (i ==0||Math.abs(i)<=57) {
            if (mCurrentState != State.EXPANDED) {
                onStateChanged(appBarLayout, State.EXPANDED,i);
            }
            mCurrentState = State.EXPANDED;

        }
//        else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) {
//            if (mCurrentState != State.COLLAPSED) {
//                onStateChanged(appBarLayout, State.COLLAPSED,i);
//            }
//            mCurrentState = State.COLLAPSED;
//
//            Log.e("onOffsetChanged","::Math:"+Math.abs(i)+"::appBarLayout:"+appBarLayout.getTotalScrollRange());
//
//
//        }
        else {
            if (Math.abs(i)>57){
                if (mCurrentState != State.IDLE) {
                    onStateChanged(appBarLayout, State.IDLE,i);
                }
                mCurrentState = State.IDLE;
            }
//            Log.e("onOffsetChanged11111111","::Math:"+Math.abs(i)+"::appBarLayout:"+appBarLayout.getTotalScrollRange());
        }
    }

    public abstract void onStateChanged(AppBarLayout appBarLayout, State state,int i);
}